package com.hjl.controller;

import com.hjl.pojo.Employee;
import com.hjl.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ServivE
 * @version 0.1
 * @className EmpController
 * @description
 * @date 2024/8/13 21:56
 * @since jdk17
 */
@Slf4j
@RestController
@RequestMapping("/employee")
public class EmpController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping("list")
    public List<Employee> retList() {
        List<Employee> employees = employeeService.findAll();
        log.info("员工数据:{}", employees);
        return employees;
    }

    //路径参数
    @GetMapping("{id}")
    public Employee findById(@PathVariable int id) {
        Employee emp = employeeService.findEmpById(id);
        return emp;
    }

    //增加一条信息  json
    @PostMapping
    public Object insertInfo(@RequestBody Employee employee) {
        int i = employeeService.insertInfo(employee);
        return "受影响" + i + "行";
    }

    //删除id为4的信息
    @DeleteMapping("{id}")
    public Object deleteInfoById(@PathVariable int id) {
        int i = employeeService.deleteInfoById(id);
        return "成功删除id为" + id + "的信息  " + i + "行";
    }

    //修改id为1的工资为1800.0
    @PutMapping
    public Object updateInfoById(@RequestBody Employee employee) {
        employeeService.updateInfoById(employee);
        return "ok";
    }
}